package com.antis.olsl.data.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import com.antis.olsl.data.R;
import com.antis.olsl.library.bean.GoodsInfo;
import com.antis.olsl.library.utils.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.math.BigDecimal;
import java.util.List;

/**
 * 调拨商品列表
 * Created by qi.yang on 2020/3/24 0008.
 */

public class AllocateGoodsListAdapter extends BaseQuickAdapter<GoodsInfo, BaseViewHolder> implements LoadMoreModule {
    public AllocateGoodsListAdapter(List<GoodsInfo> data) {
        super(R.layout.listitem_table, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsInfo item) {
        TextView tv2 = helper.getView(R.id.tv_2);
        String productName = "";
        if (!TextUtils.isEmpty(item.getProductName())) {
            if (item.getProductName().length() > 6) {
                productName = item.getProductName().substring(0, 6) + "...";
            } else {
                productName = item.getProductName();
            }
        }
        tv2.setSingleLine(true);
        tv2.setMaxLines(1);
        tv2.setEllipsize(TextUtils.TruncateAt.END);
        helper.setText(R.id.tv_1, item.getProductCode())
                .setText(R.id.tv_2, productName)
                .setText(R.id.tv_3, StringUtils.getCommaFormat(BigDecimal.valueOf(item.getAllocateNum())))
                .setText(R.id.tv_4, StringUtils.getCommaFormat(BigDecimal.valueOf(item.getAllocatePrice())));
        ((TextView) helper.getView(R.id.tv_2)).setEllipsize(TextUtils.TruncateAt.END);
        ((TextView) helper.getView(R.id.tv_2)).setSingleLine(true);
    }

}
